package cn.yuanqiao.archive.shuzihua.service.impl;

import cn.yuanqiao.archive.appManager.domain.*;
import cn.yuanqiao.archive.appManager.mapper.*;
import cn.yuanqiao.archive.appManager.service.ITenantSysConfigService;
import cn.yuanqiao.archive.chengguojieshou.mapper.YqdaarticulatedMapper;
import cn.yuanqiao.archive.sealmanage.PdfUtil;
import cn.yuanqiao.archive.sealmanage.service.ISealmanageService;
import cn.yuanqiao.archive.sealmanage.service.impl.SealmanageServiceImpl;
import cn.yuanqiao.archive.shuzihua.service.DangAnJieShouService;
import cn.yuanqiao.archive.utils.FileWaterMark;
import cn.yuanqiao.archive.wenjianzhengli.mapper.TenantItemFolderMapper;
import cn.yuanqiao.archive.wenjianzhengli.mapper.TenantYqdaFolderMapper;
import cn.yuanqiao.archive.wenjianzhengli.service.IWenjianzhengliService;
import cn.yuanqiao.common.enums.BusinessBehavior;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.util.BusinessBehaviorUtil;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.ListUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.sql.YqDatabaseSQLUtil;

import cn.yuanqiao.common.utils.SecurityUtils;
import cn.yuanqiao.common.core.domain.model.LoginUser;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.itextpdf.text.DocumentException;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zjj
 * @date 2023/7/18
 */
@Service
public class DangAnJieShouServiceImpl implements DangAnJieShouService {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private TenantCategoryMapper categoryMapper;
    @Autowired
    private TenantYqItemMapper itemMapper;
    @Autowired
    private TenantItemFolderMapper itemFolderMapper;
    @Autowired
    private TenantYqFolderMapper folderMapper;
    @Autowired
    private TenantYqdaFolderMapper yqdaFolderMapper;
    @Autowired
    private TenantYqdaMapper yqdaMapper;
    @Autowired
    private TenantMdataListMapper mdataListMapper;
    @Autowired
    private IWenjianzhengliService wenjianzhengliService;
    @Autowired
    private TenantCodeListMapper codeListMapper;
    @Autowired
    private ITenantSysConfigService sysConfigService;
    @Autowired
    private TenantCateMdataListMapper cateMdataListMapper;
    @Autowired
    private ArchiveMapper archiveMapper;
    @Autowired
    private YqdaarticulatedMapper yqdaarticulatedMapper;
    @Autowired
    private ISealmanageService sealmanageService;

    @Value("${FBswitch}")
    private boolean FBswitch;

    /**
     * 添加项目
     * @param object
     * @return
     */
    @Override
    @Transactional
    public int addItem(JSONObject object) {
        logger.info(object.toJSONString());
        //{categoryId:111,column:[{name:'TITLE',value:'标题'},{name:'BGQX',value:'D10'}]}
        Long categoryId = object.getLong("categoryId");
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        JSONArray array = object.getJSONArray("column");
        Map<String,String> column = new HashMap<>();
        for (int j = 0;j<array.size();j++){
            JSONObject data = array.getJSONObject(j);
            column.put(data.getString("name"),data.getString("value"));
        }
        //特殊字符验证
        SpecialCharacter(category.getGroupId(),3,column);
        Long id = SnowflakeIdGenerator.generateId();
        //column.put("QZH", category.getFondsCode());
        column.putAll(addCommonCol(column,category,3));

        column.put("ID",String.valueOf(id));
        TenantYqItem item = new TenantYqItem();
        item.setColNames(column);
        item.setTableName(category.getItemTableName());
        itemMapper.insertItemDisperse(item); //插入分表

        column.put("SUB_TABLE_NAME",category.getItemTableName());
        column.remove("ID");
        column.put("ITEM_ID",String.valueOf(id));
        item.setColNames(column);
        item.setTableName(new TenantYqItem().getTableName());
        int r = itemMapper.insertItem(item); //插入总表
        return r;
    }

    /**
     * 添加卷
     * @param object
     * @return
     */
    @Override
    @Transactional
    public TenantYqFolder addFolder(JSONObject object) {
        //{categoryId:111,itemId:123,column:[{name:'TITLE',value:'标题'},{name:'BGQX',value:'D10'}]}
        Long categoryId = object.getLong("categoryId");
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        Long folderId = SnowflakeIdGenerator.generateId();
        Map<String,String> column = new HashMap<>();
        //添加关联关系
        Long itemId = null;
        if(category.getType() == 3){
            if(object.containsKey("itemId") && StringUtils.isNotEmpty(object.getString("itemId"))){
                itemId = object.getLong("itemId");
                TenantItemFolder itemFolder = new TenantItemFolder();
                itemFolder.setItemId(itemId);
                itemFolder.setFolderId(folderId);
                itemFolderMapper.addItemFolder(itemFolder);
                //已组项目
                column.put("IS_PROJECT","1");
            }else {
                throw new ServiceException("参数错误！");

            }
        }
        //添加卷信息
        JSONArray array = object.getJSONArray("column");
        for (int j = 0;j<array.size();j++){
            JSONObject data = array.getJSONObject(j);
            column.put(data.getString("name"),data.getString("value"));
        }
        //验证特殊字符
        SpecialCharacter(category.getGroupId(),1,column);

        column.putAll(addCommonCol(column,category,1));

        column.put("ID",String.valueOf(folderId));
        TenantYqFolder folder = new TenantYqFolder();
        folder.setColNames(column);
        folder.setTableName(category.getFolderTableName());
        folderMapper.insertYqFolderDisperse(folder); //插入分表

        column.put("SUB_TABLE_NAME",category.getFolderTableName());
        column.remove("ID");
        column.put("FOLDER_ID",String.valueOf(folderId));
        folder.setColNames(column);
        folder.setTableName(new TenantYqFolder().getTableName());
        int r = folderMapper.insertYqFolder(folder); //插入总表

        //生成档号
        generateDH(column,category,folderId,"v");

        relevanceMap(category,1,folderId,null);
        //根据关联关系 修改操作
        if(itemId != null){
            List<String> folderIds = itemFolderMapper.selectFolderIdByItemId(String.valueOf(itemId),new TenantItemFolder().getTableName());
            relevanceMap(category,3,itemId,String.join(",",folderIds));
        }

        return folder;
    }

    /**
     * 添加件
     * @param object
     * @return
     */
    @Override
    @Transactional
    public int addYqda(JSONObject object) {
        //{categoryId:111,folderId:123,daId:456,column:[{name:'TITLE',value:'标题'},{name:'BGQX',value:'D10'}]}
        Long categoryId = object.getLong("categoryId");
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        Long daId = object.getLong("daId");
        //电子文件数默认0
        String eFileCount = "0";
        if(object.containsKey("eFileCount")){
            eFileCount = object.getString("eFileCount");
        }
        Map<String,String> column = new HashMap<>();
        column.put("EFILE_COUNT",eFileCount);
        //添加关联关系
        if(category.getType() == 1 || category.getType() == 3){
            if(object.containsKey("folderId") && StringUtils.isNotEmpty(object.getString("folderId"))){
                Long folderId = object.getLong("folderId");
                TenantYqdaFolder yqdaFolder = new TenantYqdaFolder();
                yqdaFolder.setDaId(daId);
                yqdaFolder.setFolderId(folderId);
                yqdaFolderMapper.addYqdaFolder(yqdaFolder);
                column.put("IS_ZUJUAN","1");
            }else {
                throw new ServiceException("参数错误！");
            }
        }
        //添加件信息
        JSONArray array = object.getJSONArray("column");

        for (int j = 0;j<array.size();j++){
            JSONObject data = array.getJSONObject(j);
            column.put(data.getString("name"),data.getString("value"));
        }
        //验证特殊字符
        SpecialCharacter(category.getGroupId(),0,column);

        column.putAll(addCommonCol(column,category,0));

        //卷内件的密级不能大于卷的密级
        if(category.getType() == 1 || category.getType() == 3){
            if(object.containsKey("folderId") && StringUtils.isNotEmpty(object.getString("folderId"))){
                Long folderId = object.getLong("folderId");
                Boolean bl = verifyMJ(category,folderId,null,column.get("MJ"));
                if(bl == false){
                    throw new ServiceException("卷内件的密级不能大于卷的密级！");
                }
            }
        }

        //电子文件密级不能大于件的密级
        if(FBswitch){
            /*String maxMJ = archiveMapper.getMaxMjDoc(category.getEfileTableName(),daId);
            if(StringUtils.isNotEmpty(maxMJ)){
                if(StringUtils.isEmpty(column.get("MJ"))){
                    throw new ServiceException("请填写密级信息！");
                }else {
                    Integer daMJ = Integer.valueOf(column.get("MJ"));
                    Integer docMJ = Integer.valueOf(maxMJ);
                    if(docMJ>daMJ){
                        throw new ServiceException("电子文件密级不能大于件密级！");
                    }
                }
            }*/
            //todo 电子文件密级不能大于件的密级
        }

        column.put("ID",String.valueOf(daId));
        TenantYqda yqda = new TenantYqda();
        yqda.setColNames(column);
        yqda.setTableName(category.getFileTableName());
        yqdaMapper.insertYqdaDisperse(yqda); //插入分表

        column.put("SUB_TABLE_NAME",category.getFileTableName());
        column.remove("ID");
        column.put("DA_ID",String.valueOf(daId));
        yqda.setColNames(column);
        yqda.setTableName(new TenantYqda().getTableName());
        int r = yqdaMapper.insertYqda(yqda); //插入总表

        //如果是卷内件，判断卷层档号是否有值
        if(category.getType() == 3 || category.getType() == 1){
            //验证档号字段是否有值
            if(StringUtils.isNotEmpty(column.get("RQ"))){
                //根据日期获取档号规则
                Map<String,String> rule = codeListMapper.getCodeListByRq(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),Integer.valueOf(column.get("RQ")));
                if(rule == null || rule.size()==0){
                    //使用默认档号规则
                    rule = codeListMapper.getCodeListByRq(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),null);
                }
                if(rule != null){
                    if(rule.size()!=0){
                        String jianDh = rule.get("F_COLUMNNAME"); //卷档号字段
                        Map<String,Object> folderData = folderMapper.getYqFolderById(jianDh,object.getLong("folderId"),category.getFolderTableName());
                        if(folderData!=null && folderData.get(jianDh)!=null && !"".equals(folderData.get(jianDh))){
                            //卷内件生成档号
                            JSONObject juannei = new JSONObject();
                            juannei.put("categoryId",categoryId);
                            juannei.put("folderId",object.getLong("folderId"));
                            juannei.put("ids",String.valueOf(daId));
                            wenjianzhengliService.pieceInnerNumber(juannei);
                        }
                    }
                }

            }
        }else if(category.getType() == 0){
            generateDH(column,category,daId,"f");
        }

        //根据关联关系 修改操作
        if(category.getType() == 1 || category.getType() == 3){
            if(object.containsKey("folderId") && StringUtils.isNotEmpty(object.getString("folderId"))){
                List<String> folderIds = yqdaFolderMapper.selectFolderIdByFileId(object.getString("folderId"),new TenantYqdaFolder().getTableName());
                relevanceMap(category,1,object.getLong("folderId"),String.join(",",folderIds));
            }
        }
        if(category.getType() == 3){
            if(object.containsKey("folderId") && StringUtils.isNotEmpty(object.getString("folderId"))){
                List<Long> itemIds = itemFolderMapper.getItemIdByFolderId(object.getString("folderId"),category.getFolderTableName(),new TenantItemFolder().getTableName());
                if(itemIds !=null && itemIds.size()>0){
                    List<String> folderIds = itemFolderMapper.selectFolderIdByItemId(String.valueOf(itemIds.get(0)),new TenantItemFolder().getTableName());
                    relevanceMap(category,3,itemIds.get(0),String.join(",",folderIds));
                }
            }
        }
        return r;
    }

    @Override
    @Transactional
    public int updateItem(JSONObject object) {
        //{categoryId:111,id:'123',column:[{name:'TITLE',value:'标题'},{name:'BGQX',value:'D10'}]}
        Long categoryId = object.getLong("categoryId");
        Long id = object.getLong("id");
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        JSONArray array = object.getJSONArray("column");
        Map<String,String> column = new HashMap<>();
        for (int j = 0;j<array.size();j++){
            JSONObject data = array.getJSONObject(j);
            column.put(data.getString("name"),data.getString("value"));
        }
        //验证特殊字符
        SpecialCharacter(category.getGroupId(),3,column);

        column.putAll(updateCommonCol(column,category));

        TenantYqItem item = new TenantYqItem();
        item.setColNames(column);

        item.setTableName(category.getItemTableName());
        item.setItemId(id);
        itemMapper.updateItemDisperse(item); //修改分表

        item.setTableName(new TenantYqItem().getTableName());
        int r = itemMapper.updateItem(item); //修改总表

        List<String> folderIds = itemFolderMapper.selectFolderIdByItemId(String.valueOf(id),new TenantItemFolder().getTableName());
        //更新项目
        relevanceMap(category,3,id,String.join(",",folderIds));
        for(String folderId:folderIds){
            //更新卷
            List<String> daIds = yqdaFolderMapper.selectFileIdByFolderId(folderId,new TenantYqdaFolder().getTableName());
            relevanceMap(category,1,Long.valueOf(folderId),String.join(",",daIds));
        }

        return r;
    }

    @Override
    @Transactional
    public int updateFolder(JSONObject object) {
        Long categoryId = object.getLong("categoryId");
        Long id = object.getLong("id");
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        JSONArray array = object.getJSONArray("column");
        Map<String,String> column = new HashMap<>();
        for (int j = 0;j<array.size();j++){
            JSONObject data = array.getJSONObject(j);
            column.put(data.getString("name"),data.getString("value"));
        }
        //验证特殊字符
        SpecialCharacter(category.getGroupId(),1,column);

        column.putAll(updateCommonCol(column,category));

        //卷内件的密级不能大于卷的密级
        if(column.get("MJ") != null && !"".equals(column.get("MJ"))){
            Integer juanMj = Integer.valueOf(column.get("MJ"));
            Integer jianMaxMj = yqdaMapper.getMaxJianMjByFolderIds(String.valueOf(id),category.getFileTableName(),new TenantYqdaFolder().getTableName());
            if(jianMaxMj!=null && jianMaxMj>juanMj){
                throw new ServiceException("卷内件的密级不能大于卷的密级");
            }

        }

        //获取修改之前的数据
        Map<String,Object> oldData = getOldData(category,id,"v");


        TenantYqFolder folder = new TenantYqFolder();
        folder.setColNames(column);

        folder.setTableName(category.getFolderTableName());
        folder.setFolderId(id);
        folderMapper.updateYqFolderDisperse(folder); //修改分表

        folder.setTableName(new TenantYqFolder().getTableName());
        int r = folderMapper.updateYqFolder(folder); //修改总表

        //需要从新生成档号 先清空
        Boolean bl = generateUpdateDH(oldData,category,id,"v");
        if(bl){
            JSONObject json = new JSONObject();
            json.put("categoryId",categoryId);
            json.put("ids",id);
            json.put("sub_table_name",category.getFolderTableName());
            json.put("type",category.getType());
            wenjianzhengliService.clearNumber(json);
            generateDH(column,category,id,"v");
        }

        List<String> daIds = yqdaFolderMapper.selectFileIdByFolderId(String.valueOf(id),new TenantYqdaFolder().getTableName());
        //更新卷
        relevanceMap(category,1,id,String.join(",",daIds));
        if(category.getType()==3){
            //更新项目
            List<Long> itemIds = itemFolderMapper.getItemIdByFolderId(String.valueOf(id),category.getFolderTableName(),new TenantItemFolder().getTableName());
            if(itemIds.size()>0){
                List<String> folderIds = itemFolderMapper.selectFolderIdByItemId(String.valueOf(itemIds.get(0)),new TenantItemFolder().getTableName());
                relevanceMap(category,3,itemIds.get(0),String.join(",",folderIds));
            }
        }
        return r;
    }

    @Override
    @Transactional
    public int updateYqda(JSONObject object) {
        Long categoryId = object.getLong("categoryId");
        Long id = object.getLong("id");
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        JSONArray array = object.getJSONArray("column");
        Map<String,String> column = new HashMap<>();
        for (int j = 0;j<array.size();j++){
            JSONObject data = array.getJSONObject(j);
            column.put(data.getString("name"),data.getString("value"));
        }
        //验证特殊字符
        SpecialCharacter(category.getGroupId(),0,column);
        column.putAll(updateCommonCol(column,category));

        //卷内件的密级不能大于卷的密级
        if(category.getType() == 1 || category.getType() == 3){
            //查询卷id
            Long folderId = yqdaFolderMapper.getFolderIdBydaId(id,new TenantYqdaFolder().getTableName());
            if(folderId!=null){
                Boolean bl = verifyMJ(category,folderId,null,column.get("MJ"));
                if(bl == false){
                    throw new ServiceException("卷内件的密级不能大于卷的密级！");
                }
            }
        }

        //根据档号组成字段 获取修改之前的数据
        Map<String,Object> daData = getOldData(category,id,"f");

        TenantYqda yqda = new TenantYqda();
        yqda.setColNames(column);

        yqda.setTableName(category.getFileTableName());
        yqda.setDaId(id);
        yqdaMapper.updateYqdaDisperse(yqda); //修改分表

        yqda.setTableName(new TenantYqda().getTableName());
        int r = yqdaMapper.updateYqda(yqda); //修改总表
        //生成档号相关
        //如果是卷内件，判断卷层档号是否有值
        if(category.getType() == 3 || category.getType() == 1){
            //验证档号字段是否有值
            if(StringUtils.isNotEmpty(column.get("RQ"))){
                //根据日期获取档号规则
                Map<String,String> rule = codeListMapper.getCodeListByRq(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),Integer.valueOf(column.get("RQ")));
                if(rule == null || rule.size()==0){
                    //使用默认档号规则
                    rule = codeListMapper.getCodeListByRq(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),null);
                }
                if(rule != null || rule.size()!=0){
                    String jianDh = rule.get("F_COLUMNNAME"); //卷档号字段
                    Map<String,Object> folderData = folderMapper.getYqFolderById(jianDh,id,category.getFolderTableName());
                    if(folderData != null && folderData.get(jianDh)!=null && !"".equals(folderData.get(jianDh))){
                        //卷内件生成档号
                        JSONObject juannei = new JSONObject();
                        juannei.put("categoryId",categoryId);
                        juannei.put("folderId",object.getLong("folderId"));
                        juannei.put("ids",id);
                        wenjianzhengliService.pieceInnerNumber(juannei);
                    }
                }
            }
        }else if(category.getType() == 0){

            //验证修改内容是否包含档号组成字段
            Boolean bl = generateUpdateDH(daData,category,id,"f");
            //需要从新生成档号 先清空
            if(bl){
                JSONObject json = new JSONObject();
                json.put("categoryId",categoryId);
                json.put("ids",id);
                json.put("sub_table_name",category.getFileTableName());
                json.put("type",category.getType());
                wenjianzhengliService.clearNumber(json);
                generateDH(column,category,id,"f");
            }
        }

        //更新
        if(category.getType() == 1){
            List<String> folderIds = yqdaFolderMapper.selectFolderIdByFileId(String.valueOf(id),new TenantYqdaFolder().getTableName());
            if(folderIds !=null && folderIds.size()>0){
                List<String> daIds = yqdaFolderMapper.selectFileIdByFolderId(folderIds.get(0),new TenantYqdaFolder().getTableName());
                relevanceMap(category,1,Long.valueOf(id),String.join(",",daIds));
            }
        }
        if(category.getType() == 3){
            List<String> folderIds = yqdaFolderMapper.selectFolderIdByFileId(String.valueOf(id),new TenantYqdaFolder().getTableName());
            if(folderIds !=null && folderIds.size()>0){
                List<Long> itemIds = itemFolderMapper.getItemIdByFolderId(String.join(",",folderIds),category.getFolderTableName(),new TenantItemFolder().getTableName());
                if(itemIds !=null && itemIds.size()>0){
                    relevanceMap(category,3,Long.valueOf(id),String.join(",",folderIds));
                }
            }

        }

        return r;
    }

    @Override
    @Transactional
    public Map jieshou(Long categoryId, Long[] ids) {
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        Map<String,String> column = new HashMap<>();
        column.put("STATE","5");
        String state = null;
        //判断文件是否有四性检测结果
         int count=ids.length;
         int count1=0;
        //处理项目层
        if(category.getType() == 3){
            TenantYqItem item = new TenantYqItem();
            item.setColNames(column);
            if(state==null){
                state = yqdaarticulatedMapper.getSingle("select state from " + category.getItemTableName() + " where id = " + ids[0]);
            }
         //   ids=itemMapper.getIdsByState(ids,category.getItemTableName(),"ID","FOURCHECK","1");
            count1=ids.length;
            //添加过程信息
            addBehavior(ids,state);
            itemMapper.updateItemByIds(item,ids); //主表
            item.setTableName(category.getItemTableName());
            itemMapper.updateItemDisperseByIds(item,ids);  //分表

            ids = folderMapper.getFolderIdsByItemIds(ids,category.getFolderTableName(),new TenantItemFolder().getTableName());//查询项目下的卷
            if(ids== null || ids.length==0){
                throw new ServiceException("项目下没有卷信息，接收失败！");
            }
        }else if(category.getType() == 1){
         //   ids=itemMapper.getIdsByState(ids,category.getFolderTableName(),"ID","FOURCHECK","1");
            count1=ids.length;
        }else if(category.getType() == 0){
        //    ids=itemMapper.getIdsByState(ids,category.getFileTableName(),"ID","FOURCHECK","1");
            count1=ids.length;
        }

//        if(count1==0){
//            throw new ServiceException("请进行四性检测或验证检测是否通过！");
//        }
        //获取档号存储字段
        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setIsArchiveNo(1);
        List<TenantMdataList> mdataLists = mdataListMapper.selectTenantMdataListListByCategoryId(mdataList,category.getId(),new TenantCategory().getTableName());
        String juanDhCol = "";
        String jianDhCol = "";
        for(TenantMdataList list:mdataLists){
            if(list.getType()==1){
                juanDhCol = list.getFieldName();
            }else if(list.getType()==0){
                jianDhCol = list.getFieldName();
            }
        }
        if(category.getType() == 3 || category.getType() == 1){
            if(StringUtils.isEmpty(juanDhCol) || StringUtils.isEmpty(jianDhCol)){
                throw new ServiceException("元数据没有配置档号字段！");
            }
        }else if(category.getType() == 0){
            if(StringUtils.isEmpty(jianDhCol)){
                throw new ServiceException("元数据没有配置档号字段！");
            }
        }

        //处理卷层
        if(category.getType() == 3 || category.getType() == 1){
            //验证没有档号的数据
            int notDh = folderMapper.DhIsNull(ids,juanDhCol,category.getFolderTableName());
            if(notDh == 0){
                TenantYqFolder folder = new TenantYqFolder();
                folder.setColNames(column);
                if(state==null){
                    state = yqdaarticulatedMapper.getSingle("select state from " + category.getFolderTableName() + " where id = " + ids[0]);
                }
                //添加过程信息
                addBehavior(ids,state);
                folderMapper.updateYqFolderByIds(folder,ids); //主表
                folder.setTableName(category.getFolderTableName());
                folderMapper.updateYqFolderDisperseByIds(folder,ids);

                ids = yqdaMapper.getDaIdsByFolderIds(ids,category.getFileTableName(),new TenantYqdaFolder().getTableName());//查询卷下的件
                /*if(ids== null || ids.length==0){
                    throw new ServiceException("卷下没有件信息，接收失败！");
                }*/
            }else {
                throw new ServiceException("卷下存在没有档号的数据！");
            }
        }
        //处理件层
        //验证没有档号的数据
        List<List<Long>> lists = ListUtils.subList(Arrays.asList(ids), 5000);
        for(List<Long> idds:lists){
            int notDh = yqdaMapper.DhIsNull(idds,jianDhCol,category.getFileTableName());
            if(notDh == 0){
                TenantYqda yqda = new TenantYqda();
                yqda.setColNames(column);
                if(state==null){
                    state = yqdaarticulatedMapper.getSingle("select state from " + category.getFileTableName() + " where id = " + ids[0]);
                }
                //添加过程信息
                addBehavior(ids,state);
                yqdaMapper.updateYqdaByIds(yqda,idds);
                yqda.setTableName(category.getFileTableName());
                yqdaMapper.updateYqdaDisperseByIds(yqda,idds);
                if("10".equals(state) || "2".equals(state) || "3".equals(state)){   //预归档/文件整理/档案接收 归档接收   添加归档章
                    addSeal(ids,category.getId().toString());
                }
            }else {
                throw new ServiceException("件下存在没有档号的数据！");
            }
        }
        Map map=new HashMap();
        map.put("count",count-count1);
        return map;
    }

    @Override
    @Transactional
    public Map jieshouszh(Long categoryId, Long[] ids) {
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        Map<String,String> column = new HashMap<>();
        column.put("STATE","12");
        String state = null;
        //判断文件是否有四性检测结果
        int count=ids.length;
        int count1=0;
        //处理项目层
        if(category.getType() == 3){
            TenantYqItem item = new TenantYqItem();
            item.setColNames(column);
            if(state==null){
                state = yqdaarticulatedMapper.getSingle("select state from " + category.getItemTableName() + " where id = " + ids[0]);
            }
            ids=itemMapper.getIdsByState(ids,category.getItemTableName(),"ID","FOURCHECK","1");
            count1=ids.length;
            //添加过程信息
            addBehavior(ids,state);
            itemMapper.updateItemByIds(item,ids); //主表
            item.setTableName(category.getItemTableName());
            itemMapper.updateItemDisperseByIds(item,ids);  //分表

            ids = folderMapper.getFolderIdsByItemIds(ids,category.getFolderTableName(),new TenantItemFolder().getTableName());//查询项目下的卷
            if(ids== null || ids.length==0){
                throw new ServiceException("项目下没有卷信息，接收失败！");
            }
        }else if(category.getType() == 1){
            ids=itemMapper.getIdsByState(ids,category.getFolderTableName(),"ID","FOURCHECK","1");
            count1=ids.length;
        }else if(category.getType() == 0){
            ids=itemMapper.getIdsByState(ids,category.getFileTableName(),"ID","FOURCHECK","1");
            count1=ids.length;
        }

        if(count1==0){
            throw new ServiceException("请进行四性检测或验证检测是否通过！");
        }
        //获取档号存储字段
        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setIsArchiveNo(1);
        List<TenantMdataList> mdataLists = mdataListMapper.selectTenantMdataListListByCategoryId(mdataList,category.getId(),new TenantCategory().getTableName());
        String juanDhCol = "";
        String jianDhCol = "";
        for(TenantMdataList list:mdataLists){
            if(list.getType()==1){
                juanDhCol = list.getFieldName();
            }else if(list.getType()==0){
                jianDhCol = list.getFieldName();
            }
        }
        if(category.getType() == 3 || category.getType() == 1){
            if(StringUtils.isEmpty(juanDhCol) || StringUtils.isEmpty(jianDhCol)){
                throw new ServiceException("元数据没有配置档号字段！");
            }
        }else if(category.getType() == 0){
            if(StringUtils.isEmpty(jianDhCol)){
                throw new ServiceException("元数据没有配置档号字段！");
            }
        }

        //处理卷层
        if(category.getType() == 3 || category.getType() == 1){
            //验证没有档号的数据
            int notDh = folderMapper.DhIsNull(ids,juanDhCol,category.getFolderTableName());
            if(notDh == 0){
                TenantYqFolder folder = new TenantYqFolder();
                folder.setColNames(column);
                if(state==null){
                    state = yqdaarticulatedMapper.getSingle("select state from " + category.getFolderTableName() + " where id = " + ids[0]);
                }
                //添加过程信息
                addBehavior(ids,state);
                folderMapper.updateYqFolderByIds(folder,ids); //主表
                folder.setTableName(category.getFolderTableName());
                folderMapper.updateYqFolderDisperseByIds(folder,ids);

                ids = yqdaMapper.getDaIdsByFolderIds(ids,category.getFileTableName(),new TenantYqdaFolder().getTableName());//查询卷下的件
                /*if(ids== null || ids.length==0){
                    throw new ServiceException("卷下没有件信息，接收失败！");
                }*/
            }else {
                throw new ServiceException("卷下存在没有档号的数据！");
            }
        }
        //处理件层
        //验证没有档号的数据
        List<List<Long>> lists = ListUtils.subList(Arrays.asList(ids), 5000);
        for(List<Long> idds:lists){
            int notDh = yqdaMapper.DhIsNull(idds,jianDhCol,category.getFileTableName());
            if(notDh == 0){
                TenantYqda yqda = new TenantYqda();
                yqda.setColNames(column);
                if(state==null){
                    state = yqdaarticulatedMapper.getSingle("select state from " + category.getFileTableName() + " where id = " + ids[0]);
                }
                //添加过程信息
                addBehavior(ids,state);
                yqdaMapper.updateYqdaByIds(yqda,idds);
                yqda.setTableName(category.getFileTableName());
                yqdaMapper.updateYqdaDisperseByIds(yqda,idds);
                if("10".equals(state) || "2".equals(state) || "3".equals(state)){   //预归档/文件整理/档案接收 归档接收   添加归档章
                    addSeal(ids,category.getId().toString());
                }
            }else {
                throw new ServiceException("件下存在没有档号的数据！");
            }
        }
        Map map=new HashMap();
        map.put("count",count-count1);
        return map;
    }


    @Override
    @Transactional
    public void dgdJieshou(Long categoryId, Long[] ids) {
        TenantCategory category = new TenantCategory();
        category = categoryMapper.selectTenantCategoryByID(categoryId,category.getTableName());
        Map<String,String> column = new HashMap<>();
        column.put("STATE","5");
        String state = null;
        //获取档号存储字段
        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setIsArchiveNo(1);
        List<TenantMdataList> mdataLists = mdataListMapper.selectTenantMdataListListByCategoryId(mdataList,category.getId(),new TenantCategory().getTableName());
        String juanDhCol = "";
        String jianDhCol = "";
        for(TenantMdataList list:mdataLists){
            if(list.getType()==1){
                juanDhCol = list.getFieldName();
            }else if(list.getType()==0){
                jianDhCol = list.getFieldName();
            }
        }
        if(StringUtils.isEmpty(juanDhCol) || StringUtils.isEmpty(jianDhCol)){
            throw new ServiceException("元数据没有配置档号字段！");
        }
        List<String> idList = new ArrayList<>();
        for (Long num : ids) {
            String str = String.valueOf(num);
            idList.add(str);
        }
        List<Map<String,Object>> itemList = itemFolderMapper.selectItemList(ids,new TenantItemFolder().getTableName());
        //String tenantCode = SecurityUtils.getTenantCode();
        //List<Map<String,String>> itemYqdaList = itemFolderMapper.selectItemYqdaList(ids,tenantCode,category.getFileTableName());
        //处理卷层
        //验证没有档号的数据
        int notDh = folderMapper.DhIsNull(ids,juanDhCol,category.getFolderTableName());
        if(notDh == 0){
            TenantYqFolder folder = new TenantYqFolder();
            folder.setColNames(column);
            if(state==null){
                state = yqdaarticulatedMapper.getSingle("select state from " + category.getFolderTableName() + " where id = " + ids[0]);
            }
            //添加过程信息
            addBehavior(ids,state);
            folderMapper.updateYqFolderByIds(folder,ids); //主表
            folder.setTableName(category.getFolderTableName());
            folderMapper.updateYqFolderDisperseByIds(folder,ids);

            ids = yqdaMapper.getDaIdsByFolderIds(ids,category.getFileTableName(),new TenantYqdaFolder().getTableName());//查询卷下的件
                /*if(ids== null || ids.length==0){
                    throw new ServiceException("卷下没有件信息，接收失败！");
                }*/
        }else {
            throw new ServiceException("卷下存在没有档号的数据！");
        }

        //处理件层
        //验证没有档号的数据
        List<List<Long>> lists = ListUtils.subList(Arrays.asList(ids), 5000);
        for(List<Long> idds:lists){
            int notDhJ = yqdaMapper.DhIsNull(idds,jianDhCol,category.getFileTableName());
            if(notDhJ == 0){
                TenantYqda yqda = new TenantYqda();
                yqda.setColNames(column);
                if(state==null){
                    state = yqdaarticulatedMapper.getSingle("select state from " + category.getFileTableName() + " where id = " + ids[0]);
                }
                //添加过程信息
                addBehavior(ids,state);
                yqdaMapper.updateYqdaByIds(yqda,idds);
                yqda.setTableName(category.getFileTableName());
                yqdaMapper.updateYqdaDisperseByIds(yqda,idds);
                if("10".equals(state) || "2".equals(state)){   //预归档/文件整理 归档接收   添加归档章
                    addSeal(ids,category.getId().toString());
                }
            }else {
                throw new ServiceException("件下存在没有档号的数据！");
            }
        }

        //更新项目层归档卷数 和 件数
        for(Map<String,Object> item:itemList){
            //归档案卷数量
            Integer numJuan = itemFolderMapper.getFolderNumByItemIdYGD(category.getFolderTableName(),SecurityUtils.getTenantCode(), String.valueOf(item.get("ITEM_ID")));
            //itemMapper.updateItemSum("GDAJSL",numJuan,new TenantYqItem().getTableName(),item.get("ITEM_ID"));
            //itemMapper.updateItemSumDisperse("GDAJSL",numJuan,category.getItemTableName(),item.get("ITEM_ID"));
            //归档文件数量
            Integer numJian = itemFolderMapper.getDaNumByItemIdYGD(category.getFileTableName(),category.getFolderTableName(),SecurityUtils.getTenantCode(), String.valueOf(item.get("ITEM_ID")));
            //itemMapper.updateItemSum("GDWJSL",numJian,new TenantYqItem().getTableName(),item.get("ITEM_ID"));
            //itemMapper.updateItemSumDisperse("GDWJSL",numJian,category.getItemTableName(),item.get("ITEM_ID"));
            TenantYqItem yqItem = new TenantYqItem();
            Map<String,String> data = new HashMap<>();
            data.put("GDAJSL", String.valueOf(numJuan));
            data.put("GDWJSL", String.valueOf(numJian));
            yqItem.setColNames(data);
            yqItem.setItemId(Long.valueOf(String.valueOf(item.get("ITEM_ID"))));
            itemMapper.updateItem(yqItem);
            yqItem.setTableName(category.getItemTableName());
            itemMapper.updateItemDisperse(yqItem);
        }
        /*for(Map<String,String> item:itemList){
            //归档案卷数量
            int num = item.get("NUM") == null ? 0:Integer.valueOf(item.get("NUM"));
            itemMapper.updateItemSum("GDAJSL",num,new TenantYqItem().getTableName(),item.get("ITEM_ID"));
            itemMapper.updateItemSumDisperse("GDAJSL",num,category.getItemTableName(),item.get("ITEM_ID"));
        }*/

        //更新项目层归档卷数 和 件数
        /*for(Map<String,String> item:itemYqdaList){
            //归档文件数量
            int num = item.get("NUM") == null ? 0:Integer.valueOf(item.get("NUM"));
            itemMapper.updateItemSum("GDWJSL",num,new TenantYqItem().getTableName(),item.get("ITEM_ID"));
            itemMapper.updateItemSumDisperse("GDWJSL",num,category.getItemTableName(),item.get("ITEM_ID"));
        }*/
    }

    public void addSeal(Long[] ids,String categoryId) {
        String tenantCode = SecurityUtils.getTenantCode();
        boolean isAdd = true;
        List<Map<String, Object>> maps1 = yqdaarticulatedMapper.executeSql("select config_value " +
                " from sys_config where config_key = 'SEAL_POSITION' AND TENANTCODE = '" + tenantCode + "'");
        String config_value = "";
        if(null==maps1 || maps1.size()==0 || maps1.get(0)==null){
            System.out.println("归档章路径未配置");
            isAdd = false;
        }else{
            config_value = String.valueOf(maps1.get(0).get("CONFIG_VALUE"));
            if(StringUtils.isEmpty(config_value) || "null".equals(config_value)){
                System.out.println("归档章路径未配置");
                isAdd = false;
            }else{
                File file = new File(config_value + File.separator + tenantCode);
                if(!file.exists()){
                    file.mkdirs();
                }
            }
        }

        Map<String, Object> styleMap = new HashMap<>();
        if(ids.length!=0){
            List<Map<String, Object>> list = yqdaarticulatedMapper.executeSql("select id,state,category_id,image_path,x_position,y_position,total_height,total_width,TABLE_STYLE,total_height_px,total_width_px from " + tenantCode + "_SEALMANAGE" +
                    " WHERE (CATEGORY_ID = "+categoryId+" or CATEGORY_ID is null) and state = 1");
            if(list==null || list.size()==0){
                isAdd = false;
            }else{
                if(list.size()==1){
                    styleMap = list.get(0);
                }
                if(list.size()>1){
                    for(int i=0;i<list.size();i++){
                        Map<String, Object> map1 = list.get(i);
                        String cateId = String.valueOf(map1.get("CATEGORY_ID"));
                        if(cateId.equals(categoryId)){
                            styleMap = map1;
                            break;
                        }
                    }
                }
            }
        }
        if(isAdd){
            List<Map<String, Object>> maps = yqdaarticulatedMapper.executeSql("select efile_table_name,file_table_name from " + tenantCode + "_category where id = " + categoryId + "");
            String tableName = String.valueOf(maps.get(0).get("EFILE_TABLE_NAME"));
            String fileTableName = String.valueOf(maps.get(0).get("FILE_TABLE_NAME"));
            String x_position = String.valueOf(styleMap.get("X_POSITION"));
            String y_position = String.valueOf(styleMap.get("Y_POSITION"));
            String total_height = String.valueOf(styleMap.get("TOTAL_HEIGHT"));
            total_height = String.valueOf(styleMap.get("TOTAL_HEIGHT_PX"));
            String total_width = String.valueOf(styleMap.get("TOTAL_WIDTH"));
            total_width = String.valueOf(styleMap.get("TOTAL_WIDTH_PX"));
            String image_path = String.valueOf(styleMap.get("IMAGE_PATH"));
            String table_style = String.valueOf(styleMap.get("TABLE_STYLE"));
            String sealManageId = String.valueOf(styleMap.get("ID"));
            JSONArray jsonArray = JSONArray.parseArray(table_style);
            String columnStr = "";
            for(int i = 0;i<jsonArray.size();i++){
                JSONArray ja =new JSONArray();
                if(jsonArray.get(i) instanceof JSONArray){
                    ja=(JSONArray)jsonArray.get(i);
                }else if(jsonArray.get(i) instanceof JSONObject){
                    ja.add(jsonArray.get(i));
                }
                for(int j=0;j<ja.size();j++){
                    JSONObject jb = (JSONObject)ja.get(j);
                    String type = String.valueOf(jb.get("type"));
                    if("2".equals(type)){  //动态值
                        JSONObject value = (JSONObject) jb.get("value");
                        columnStr += value.get("value") + ",";
                    }
                }
            }
            if(columnStr.endsWith(",")) columnStr = columnStr.substring(0,columnStr.length()-1);
            for (Long id:ids){
                String daId = id.toString();
                List<Map<String, Object>> maps2 = new ArrayList<>();
                List<Map<String, Object>> list = yqdaarticulatedMapper.executeSql("select doc_id,path,DOC_MNT,doc_file_type,real_doc_name from " + tableName + " where is_del=0 and " +
                            "con_table_id = " + daId + "");
                for(int j=0;j<list.size();j++){
                    Map<String, Object> map = list.get(j);
                    String type = String.valueOf(map.get("DOC_FILE_TYPE"));
                    if("pdf".equalsIgnoreCase(type)){
                        String path = String.valueOf(map.get("PATH"));
                        String doc_mnt = String.valueOf(map.get("DOC_MNT"));
                        Boolean aBoolean = FileWaterMark.PdfIsEncryption(doc_mnt + path);
                        if(aBoolean){
                            logger.info("{}加密不添加水印",doc_mnt + path);
                            continue;
                        }
                        String real_doc_name = String.valueOf(map.get("REAL_DOC_NAME"));
                        String doc_id = String.valueOf(map.get("DOC_ID"));
                        if(!"".equals(columnStr))
                            maps2 = yqdaarticulatedMapper.executeSql("select "+columnStr+" from "+fileTableName+" where id = " +
                                    "(select con_table_id from "+tableName+" where doc_id = "+doc_id+")");

                        String imagePath = sealmanageService.getImagePath(Long.valueOf(sealManageId), maps2.size()!=0? JSON.toJSONString(maps2):"null");

                        try {
                            InputStream inputStream = new FileInputStream(new File(doc_mnt+path));
                            //生成归档章图片
                            ByteArrayOutputStream qRcodePngStream = SealmanageServiceImpl.getQRcodePngStream(imagePath);
                            byte[] data = qRcodePngStream.toByteArray();
                            String newPath = config_value + File.separator + tenantCode + File.separator + real_doc_name;
                            PdfUtil.addImage(inputStream,newPath,data,Integer.valueOf(x_position),Integer.valueOf(y_position),Integer.valueOf(total_width),Integer.valueOf(total_height),"0".equals(image_path)?true:false);
                            //有归档章的覆盖无归档章的
                            FileUtils.copyFile(new File(newPath),new File(doc_mnt+path));
                            File file = new File(newPath);
                            if(file.exists()){   //删除临时文件
                                file.delete();
                            }
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        } catch (DocumentException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        //}

                    }
                }

            }
        }
    }

    public void addBehavior(Long[] ids,String state){
        BusinessBehavior behavior = null;
        if("10".equals(state)){
            behavior = BusinessBehavior.GUIDANG;
        }
        if("3".equals(state)){
            behavior = BusinessBehavior.JIESHOU;
        }
        if(null!=behavior){
            List<Long> daIds = Arrays.asList(ids);
            BusinessBehaviorUtil.add(daIds, behavior);
        }
    }

    private Map<String,Object> getOldData(TenantCategory category, Long daId, String type){
        Map<String,Object> daData = null;
        Map<String,Object> rq = null;
        //获取RQ的值
        if("v".equals(type)){
            rq = folderMapper.getYqFolderById("RQ",daId,category.getFolderTableName());
        }else if("f".equals(type)){
            rq = yqdaMapper.getYqdaById("RQ",daId,category.getFileTableName());
        }
        if(rq!=null && !"".equals(String.valueOf(rq.get("RQ")))){
            List<Map<String,String>> rule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),
                    Integer.valueOf(String.valueOf(rq.get("RQ"))),"著录项值",type);
            if(rule == null || rule.size()==0){
                //使用默认档号规则
                rule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),null,"著录项值",type);
            }
            if(rule != null && rule.size()>0){
                List<String> ruleList = new ArrayList<>();
                StringBuilder selectSql = new StringBuilder();
                for(int i = 0;i<rule.size()-1;i++){
                    ruleList.add(rule.get(i).get("NODE_VALUE"));
                    selectSql.append(rule.get(i).get("NODE_VALUE")+",");
                }
                if(selectSql.length()>0){
                    selectSql.deleteCharAt(selectSql.length()-1);
                    //根据档号组成获取值
                    if("v".equals(type)){
                        daData = folderMapper.getYqFolderById(selectSql.toString(),daId,category.getFolderTableName());
                    }else if("f".equals(type)){
                        daData = yqdaMapper.getYqdaById(selectSql.toString(),daId,category.getFileTableName());
                    }
                    daData.put("RQ",rq.get("RQ"));
                }
            }
        }
        return daData;
    }

    private Boolean generateUpdateDH(Map<String,Object> column, TenantCategory category, Long daId, String type){
        Boolean bl = false;
        Map<String,Object> rq = null;
        //获取新RQ字段
        if("v".equals(type)){
            rq = folderMapper.getYqFolderById("RQ",daId,category.getFolderTableName());
        }else if("f".equals(type)){
            rq = yqdaMapper.getYqdaById("RQ",daId,category.getFileTableName());
        }
        if(rq!=null && !"".equals(String.valueOf(rq.get("RQ")))){
            //根据新日期获取档号规则
            List<Map<String,String>> rule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),
                    Integer.valueOf(String.valueOf(rq.get("RQ"))),"著录项值",type);
            if(rule == null || rule.size()==0){
                //使用默认档号规则
                rule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),null,"著录项值",type);
            }
            if(rule != null && rule.size()>0){
                //旧RQ字段值 两次使用的档号规则不一致
                if(column!=null && !"".equals(String.valueOf(column.get("RQ")))){
                    List<Map<String,String>> oldRule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),
                            Integer.valueOf(String.valueOf(column.get("RQ"))),"著录项值",type);
                    if(oldRule == null || oldRule.size()==0){
                        //使用默认档号规则
                        oldRule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),null,"著录项值",type);
                    }
                    if((rule != null && rule.size()>0) && (oldRule!=null && oldRule.size()>0) && !String.valueOf(rule.get(0).get("ID")).equals(String.valueOf(oldRule.get(0).get("ID")))){
                        bl = true;
                    }
                }
            }else {
                bl = true;
            }

            if(rule != null && rule.size()>0 && bl == false){
                List<String> ruleList = new ArrayList<>();
                StringBuilder selectSql = new StringBuilder();
                for(int i = 0;i<rule.size()-1;i++){
                    ruleList.add(rule.get(i).get("NODE_VALUE"));
                    selectSql.append(rule.get(i).get("NODE_VALUE")+",");
                }
                if(selectSql.length()>0){
                    //selectSql.deleteCharAt(selectSql.length()-1);
                    Map<String,Object> data = null;
                    if("v".equals(type)){
                        selectSql.append(rule.get(0).get("V_COLUMNNAME"));
                        data = folderMapper.getYqFolderById(selectSql.toString(),daId,category.getFolderTableName());
                    }else if("f".equals(type)){
                        selectSql.append(rule.get(0).get("F_COLUMNNAME"));
                        data = yqdaMapper.getYqdaById(selectSql.toString(),daId,category.getFileTableName());
                    }
                    //判断档号值是否为空，如果为空直接判断需要重新生成
                    if("v".equals(type) && (data.get(rule.get(0).get("V_COLUMNNAME")) == null || "".equals(data.get(rule.get(0).get("V_COLUMNNAME"))))){
                        bl = true;
                    }else if("f".equals(type) && (data.get(rule.get(0).get("F_COLUMNNAME")) == null || "".equals(data.get(rule.get(0).get("F_COLUMNNAME"))))){
                        bl = true;
                    }
                    if(bl == false){
                        for(String node:ruleList){
                            if((data.get(node)==null||"".equals(String.valueOf(data.get(node)))) && (column.get(node)!= null && !"".equals(String.valueOf(data.get(node))))){
                                //原来没值 现在有值
                                bl = true;
                            }else if((data.get(node)!=null && !"".equals(String.valueOf(data.get(node)))) && (column.get(node)== null || "".equals(String.valueOf(data.get(node))))){
                                //原来有值 现在没值
                                bl = true;
                            }else if(data.get(node)!=null && column.get(node)!= null && !String.valueOf(data.get(node)).equals(String.valueOf(column.get(node)))){
                                //现在有值 原来也有值 但是值不一致
                                bl = true;
                            }
                        }
                    }
                }
            }
        }
        return bl;
    }

    /**
     * 验证档案字段是否有数据
     * @param column 著录值
     * @param category 门类
     * @param daId 档案id
     * @param type v f
     */
    private void generateDH(Map<String,String> column, TenantCategory category, Long daId, String type){
        //验证档号字段是否有值
        if(StringUtils.isNotEmpty(column.get("RQ"))){
            //根据日期获取档号规则
            List<Map<String,String>> rule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),
                    Integer.valueOf(column.get("RQ")),"著录项值",type);
            if(rule == null || rule.size()==0){
                //使用默认档号规则
                rule = codeListMapper.getCodeListByCategoryId(category.getId(),new TenantCodeList().getTableName(),new TenantCodeRule().getTableName(),null,"著录项值",type);
            }
            if(rule != null || rule.size()!=0){
                List<String> ruleList = new ArrayList<>();
                StringBuilder selectSql = new StringBuilder();
                //不需要验证最后一位，最后一位一般是卷号或者件号，由系统自动生成
                for(int i = 0;i<rule.size()-1;i++){
                    ruleList.add(rule.get(i).get("NODE_VALUE"));
                    selectSql.append(rule.get(i).get("NODE_VALUE")+",");
                }
                if(selectSql.length()>0){
                    selectSql.deleteCharAt(selectSql.length()-1);
                    //获取档号字段的值
                    String tableName = "v".equals(type) ? category.getFolderTableName():category.getFileTableName();
                    Map<String, Object> data = folderMapper.getYqFolderById(selectSql.toString(),daId,tableName);
                    if(data!=null && data.size()>0){
                        Boolean bl = true;
                        for(String col:ruleList){
                            if(data.get(col) == null || "".equals(data.get(col))){
                                //档号字段存在空值
                                bl = false;
                                break;
                            }
                        }
                        if(bl){
                            Map<String,String> finalIds = new HashMap<>();
                            //生成档号
                            finalIds.put(String.valueOf(daId),column.get("RQ"));
                            String typeStr = "v".equals(type) ? "1":"0";
                            wenjianzhengliService.generateDH(String.valueOf(category.getId()),typeStr,finalIds,tableName,category.getFileTableName());
                        }
                    }
                }
            }
        }
    }

    /**
     * 卷内件的密级不能大于卷的密级
     * @param category
     * @param folderId
     * @param daId
     * @param daMJ
     * @return false 没有通过验证
     */
    private Boolean verifyMJ(TenantCategory category, Long folderId, Long daId, String daMJ){
        //查询卷
        Map<String,Object> data = folderMapper.getYqFolderById("MJ",folderId,category.getFolderTableName());
        if(data != null && data.size()>0 && data.get("MJ")!=null && !"".equals(String.valueOf(data.get("MJ")))){
            Integer folderMj = Integer.valueOf(String.valueOf(data.get("MJ")));
            //优先使用
            Integer mj = 0;
            if(daId!=null){
                Map<String,Object> daData = yqdaMapper.getYqdaById("MJ",daId,category.getFileTableName());
                if(daData != null && daData.size()>0 && daData.get("MJ")!=null && !"".equals(String.valueOf(daData.get("MJ")))){
                    mj = Integer.valueOf(String.valueOf(daData.get("MJ")));
                }else {
                    return true;
                }
            }else if(StringUtils.isNotEmpty(daMJ)){
                mj = Integer.valueOf(daMJ);
            }else {
                return true;
            }
            if(mj>folderMj){
                return false;
            }else {
                return true;
            }
        }else {
            return true;
        }
    }

    /**
     * 修改的公共字段
     * @param map
     * @param category
     * @return
     */
    private Map<String,String> updateCommonCol(Map<String,String> map, TenantCategory category){
        LoginUser user = SecurityUtils.getLoginUser();
        if(!map.containsKey("UPDATE_BY")){
            map.put("UPDATE_BY",user.getUsername());
        }
        if(!map.containsKey("UPDATE_TIME")){
            map.put("UPDATE_TIME", DateUtils.getTime());
        }
        /*if(category.getType() == 0 || category.getType() == 1){
            if(StringUtils.isNotEmpty(map.get("GDCS"))){
                //有值前端传的也是ID
                SysDept sysDept = remoteSysDeptService.getInfoApi(Long.valueOf(map.get("GDCS"))).getData();
                map.put("GDCS",sysDept.getDeptName());
                map.put("GDCS_ID", String.valueOf(sysDept.getDeptId()));
            }
            if(StringUtils.isNotEmpty(map.get("GDSJ"))){
                //有值前端传的也是ID
                SysDept sysDept = remoteSysDeptService.getInfoApi(Long.valueOf(map.get("GDSJ"))).getData();
                map.put("GDSJ",sysDept.getDeptName());
                map.put("GDSJ_ID", String.valueOf(sysDept.getDeptId()));
            }
        }*/
        return map;
    }

    /**
     * 添加公共列
     * @param map
     * @return
     */
    private Map<String,String> addCommonCol(Map<String,String> map, TenantCategory category, Integer type){

        //元数据中的默认值
        TenantMdataList mdataList = new TenantMdataList();
        mdataList.setType(type);
        List<TenantMdataList> tenantMdataLists = mdataListMapper.selectNotEmptyDefaultByCategoryId(mdataList,category.getId(),new TenantCategory().getTableName());
        for (TenantMdataList list:tenantMdataLists){
            if(!map.containsKey(list.getFieldName())){
                map.put(list.getFieldName(),list.getDefaultValue());
            }
        }

        LoginUser user = SecurityUtils.getLoginUser();
        if(!map.containsKey("STATE")){
            /*1:预归档-未接收
            2:预归档-已接收
            3:数字化成果未接收
            4:归档审批中
            5:已归档
            6:移交审批中
            7:已移交*/
            map.put("STATE","3");
        }
        if(!map.containsKey("JS_TYPE")){
            /*0:离线接收
            1:在线接收
            2:档案接收
            3:档案征集
            4:接收管理
            */
            map.put("JS_TYPE","2");
        }
        if(!map.containsKey("CREATE_BY")){
            map.put("CREATE_BY",user.getUsername());
        }
        if(!map.containsKey("CREATE_ID")){
            map.put("CREATE_ID",String.valueOf(user.getUserId()));
        }
        if(!map.containsKey("CREATE_TIME")){
            map.put("CREATE_TIME",DateUtils.getTime());
        }
        if(!map.containsKey("IS_INDEX")){
            map.put("IS_INDEX","0");
        }
        if(!map.containsKey("IS_DEL")){
            map.put("IS_DEL","0");
        }
        if(!map.containsKey("GDCS")){
            map.put("GDCS",user.getUser().getDept().getDeptName());
            map.put("GDCS_ID", String.valueOf(user.getUser().getDept().getDeptId()));
        }/*else if(StringUtils.isNotEmpty(map.get("GDCS"))){
                //有值前端传的也是ID
                SysDept sysDept = remoteSysDeptService.getInfoApi(Long.valueOf(map.get("GDCS"))).getData();
                map.put("GDCS",sysDept.getDeptName());
                map.put("GDCS_ID", String.valueOf(sysDept.getDeptId()));
            }*/
        if(type == 0 || type == 1){
            if(!map.containsKey("GDSJ")){
                map.put("GDSJ",user.getUser().getDept().getParentName());
                map.put("GDSJ_ID", String.valueOf(user.getUser().getDept().getParentId()));
            }/*else if(StringUtils.isNotEmpty(map.get("GDSJ"))){
                //有值前端传的也是ID
                SysDept sysDept = remoteSysDeptService.getInfoApi(Long.valueOf(map.get("GDSJ"))).getData();
                map.put("GDSJ",sysDept.getDeptName());
                map.put("GDSJ_ID", String.valueOf(sysDept.getDeptId()));
            }*/
            if(!map.containsKey("QZH")){
                map.put("QZH",category.getFondsCode());
            }
            if(!map.containsKey("TYPE")){
                map.put("TYPE",category.getCode());
            }
        }


        return map;
    }

    /**
     * 验证非法字符
     * NormalCharacter 是可以允许输入的字符
     * \u4E00-\u9FA5a-zA-Z0-9  大小写字母数字中文
     * SpecialCharacter 其他被允许的字符
     * @param groupId
     * @param type
     * @param data
     */
    private void SpecialCharacter(Long groupId,Integer type,Map<String,String> data){
        String normalCharacter = sysConfigService.selectConfigByKey("NormalCharacter");
        if(StringUtils.isNotEmpty(normalCharacter)){
            normalCharacter = normalCharacter.replaceAll("\\[","").replaceAll("]","");
            TenantMdataList mdataList = new TenantMdataList();
            mdataList.setGroupId(groupId);
            mdataList.setType(type);
            List<TenantMdataList> specialCharacter = mdataListMapper.selectSpecialCharacter(mdataList);
            String pattern = "";
            for (Map.Entry<String, String> entry : data.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                Boolean zzkh = false,yzkh = false,fxg = false,zkh = false,ykh = false,fh = false;
                if(StringUtils.isNotEmpty(value)){
                    Boolean isExist = false;
                    String name = "";
                    if(specialCharacter != null && specialCharacter.size()>0){
                        for(TenantMdataList mdata:specialCharacter){
                            if(key.equals(mdata.getFieldName())){
                                isExist = true;
                                String pat = mdata.getSpecialCharacter();
                                if(pat.indexOf("[")>-1){
                                    zzkh = true;
                                }
                                if(pat.indexOf("]")>-1){
                                    yzkh = true;
                                }
                                if(pat.indexOf("\\")>-1){
                                    fxg = true;
                                }
                                if(pat.indexOf("(")>-1){
                                    zkh = true;
                                }
                                if(pat.indexOf(")")>-1){
                                    ykh = true;
                                }
                                if(pat.indexOf(";")>-1){
                                    fh = true;
                                }
                                pat = normalCharacter + pat.replaceAll("\\[","")
                                        .replaceAll("]","")
                                        .replaceAll("\\\\","")
                                        .replaceAll("\\(","")
                                        .replaceAll("\\)","")
                                        .replaceAll(";","");
                                pattern = "["+pat+"]+";
                                name = mdata.getFieldCaption();
                                break;
                            }
                        }
                    }
                    if(zzkh && value.indexOf("[")>-1){
                        value = value.replaceAll("\\[","");
                    }
                    if(yzkh && value.indexOf("]")>-1){
                        value = value.replaceAll("]","");
                    }
                    if(fxg && value.indexOf("\\")>-1){
                        value = value.replaceAll("\\\\","");
                    }
                    if(zkh && value.indexOf("(")>-1){
                        value = value.replaceAll("\\(","");
                    }
                    if(ykh && value.indexOf(")")>-1){
                        value = value.replaceAll("\\)","");
                    }
                    if(fh && value.indexOf(";")>-1){
                        value = value.replaceAll(";","");
                    }
                    if(!isExist){
                        //没有元数据方案的配置就使用默认
                        pattern = "["+normalCharacter+"]+";
                    }
                    // 创建Pattern对象
                    Pattern regex = Pattern.compile(pattern);
                    // 创建Matcher对象
                    Matcher matcher = regex.matcher(value);
                    // 检查是否匹配到特殊字符
                    if(!matcher.matches()){
                        throw new ServiceException(name+"存在非法字符！");
                    }
                }
            }
        }

    }

    /**
     *
     * @param category
     * @param type
     * @param id 著录档案的id
     * @param ids
     * type = 3(项目) 时 ids是卷id
     * type = 1(卷) 时 ids是件id
     * type = 0(件)
     */
    private void relevanceMap(TenantCategory category, Integer type, Long id, String ids){
        TenantRelevance select = new TenantRelevance();
        select.setFieldLevel(type);
        select.setGroupId(category.getGroupId());
        List<TenantRelevance> list = cateMdataListMapper.getrelevancelist(select);
        if(list != null && list.size()>0){
            for(TenantRelevance relevance:list){
                if(type == 3){ //著录项目
                    Map<String,String> data = new HashMap<>();
                    if(relevance.getRelefieldLevel() == 3){
                        if(relevance.getRelation() == 0){  //等于关系
                            Map<String, Object> itemData = archiveMapper.getArchiveDataById(relevance.getFieldName(),id,category.getItemTableName());
                            if(itemData !=null && itemData.get(relevance.getFieldName())!=null && !"".equals(String.valueOf(itemData.get(relevance.getFieldName())))){
                                data.put(relevance.getReleField(),String.valueOf(itemData.get(relevance.getFieldName())));
                            }
                        }
                    }else if(relevance.getRelefieldLevel() == 1){ //关联卷层
                        if(StringUtils.isNotEmpty(ids)){
                            if(relevance.getRelation() == 0){  //等于关系
                                Map<String, Object> itemData = archiveMapper.getArchiveDataById(relevance.getFieldName(),id,category.getItemTableName());
                                if(itemData !=null && itemData.get(relevance.getFieldName())!=null && !"".equals(String.valueOf(itemData.get(relevance.getFieldName())))){
                                    data.put(relevance.getReleField(),String.valueOf(itemData.get(relevance.getFieldName())));
                                }
                            }else if(relevance.getRelation() == 5){  //COUNT关系
                                int countData = archiveMapper.getCOUNTData(ids,category.getFolderTableName());
                                data.put(relevance.getFieldName(),String.valueOf(countData));
                            }else if(relevance.getRelation() == 6){  //SUM关系
                                int sumData = archiveMapper.getSUMData(YqDatabaseSQLUtil.YQ_ISNULL("SUM("+relevance.getReleField()+")","0"),ids,category.getFolderTableName());
                                data.put(relevance.getFieldName(),String.valueOf(sumData));
                            }
                        }else {
                            if(relevance.getRelation() == 5){  //COUNT关系
                                int countData = 0;
                                data.put(relevance.getFieldName(),String.valueOf(countData));
                            }else if(relevance.getRelation() == 6){  //SUM关系
                                int sumData = 0;
                                data.put(relevance.getFieldName(),String.valueOf(sumData));
                            }
                        }
                    }else if(relevance.getRelefieldLevel() == 0){ //关联件层
                        if(StringUtils.isNotEmpty(ids)){
                            //所有卷下的件
                            List<String> daIds = yqdaFolderMapper.selectFileIdByFolderId(ids,new TenantYqdaFolder().getTableName());
                            if(daIds != null && daIds.size()>0){
                                if(relevance.getRelation() == 0){  //等于关系
                                    Map<String, Object> itemData = archiveMapper.getArchiveDataById(relevance.getFieldName(),id,category.getItemTableName());
                                    if(itemData !=null && itemData.get(relevance.getFieldName())!=null && !"".equals(String.valueOf(itemData.get(relevance.getFieldName())))){
                                        data.put(relevance.getReleField(),String.valueOf(itemData.get(relevance.getFieldName())));
                                    }
                                }else if(relevance.getRelation() == 5){  //COUNT关系
                                    int countData = archiveMapper.getCOUNTData(String.join(",", daIds),category.getFileTableName());
                                    data.put(relevance.getFieldName(),String.valueOf(countData));
                                }else if(relevance.getRelation() == 6){  //SUM关系
                                    int sumData = archiveMapper.getSUMData(YqDatabaseSQLUtil.YQ_ISNULL("SUM("+relevance.getReleField()+")","0"),String.join(",", daIds),category.getFileTableName());
                                    data.put(relevance.getFieldName(),String.valueOf(sumData));
                                }
                            }else {
                                //卷下没有件直接赋值为0
                                if(relevance.getRelation() == 5){  //COUNT关系
                                    data.put(relevance.getFieldName(),"0");
                                }else if(relevance.getRelation() == 6){  //SUM关系
                                    data.put(relevance.getFieldName(),"0");
                                }
                            }
                        } else {
                            //卷下没有件直接赋值为0
                            if(relevance.getRelation() == 5){  //COUNT关系
                                data.put(relevance.getFieldName(),"0");
                            }else if(relevance.getRelation() == 6){  //SUM关系
                                data.put(relevance.getFieldName(),"0");
                            }
                        }
                    }
                    if(data.size()>0){
                        if(relevance.getRelefieldLevel() == 3){
                            TenantYqItem yqItem = new TenantYqItem();
                            yqItem.setItemId(id);
                            yqItem.setColNames(data);
                            itemMapper.updateItem(yqItem);
                            yqItem.setTableName(category.getItemTableName());
                            itemMapper.updateItemDisperse(yqItem);
                        }else if(relevance.getRelation() == 0){
                            //等于关系 最终修改的是卷层或者件层
                            if(StringUtils.isNotEmpty(ids)){
                                String [] folderIds = ids.split(",");
                                if(relevance.getRelefieldLevel() == 1){
                                    for(String folderId:folderIds){
                                        TenantYqFolder yqFolder = new TenantYqFolder();
                                        yqFolder.setFolderId(Long.valueOf(folderId));
                                        yqFolder.setColNames(data);
                                        folderMapper.updateYqFolder(yqFolder);
                                        yqFolder.setTableName(category.getFolderTableName());
                                        folderMapper.updateYqFolderDisperse(yqFolder);
                                    }
                                }else if(relevance.getRelefieldLevel() == 0){
                                    for(String folderId:folderIds){
                                        List<String> daIds = yqdaFolderMapper.selectFileIdByFolderId(folderId,new TenantYqdaFolder().getTableName());
                                        for(String daId:daIds){
                                            TenantYqda yqda = new TenantYqda();
                                            yqda.setDaId(Long.valueOf(daId));
                                            yqda.setColNames(data);
                                            yqdaMapper.updateYqda(yqda);
                                            yqda.setTableName(category.getFileTableName());
                                            yqdaMapper.updateYqdaDisperse(yqda);
                                        }
                                    }
                                }
                            }
                        }else if(relevance.getRelation() == 5 || relevance.getRelation() == 6){  //COUNT关系；SUM关系 修改的是项目层
                            TenantYqItem yqItem = new TenantYqItem();
                            yqItem.setItemId(id);
                            yqItem.setColNames(data);
                            itemMapper.updateItem(yqItem);
                            yqItem.setTableName(category.getItemTableName());
                            itemMapper.updateItemDisperse(yqItem);
                        }

                    }
                }else if(type == 1){ //著录卷
                    Map<String,String> data = new HashMap<>();
                    if(relevance.getRelefieldLevel() == 1){
                        if(relevance.getRelation() == 0) {
                            Map<String,Object> archiveData = archiveMapper.getArchiveDataById(relevance.getFieldName(),id,category.getFolderTableName());
                            if(archiveData !=null && archiveData.get(relevance.getFieldName()) !=null && !"".equals(String.valueOf(archiveData.get(relevance.getFieldName())))){
                                data.put(relevance.getReleField(),String.valueOf(archiveData.get(relevance.getFieldName())));
                            }
                        }
                    }else if(relevance.getRelefieldLevel() == 0){
                        if(StringUtils.isNotEmpty(ids)){
                            if(relevance.getRelation() == 0) {  //等于关系
                                Map<String,Object> archiveData = archiveMapper.getArchiveDataById(relevance.getFieldName(),id,category.getFolderTableName());
                                if(archiveData !=null && archiveData.get(relevance.getFieldName()) !=null && !"".equals(String.valueOf(archiveData.get(relevance.getFieldName())))){
                                    data.put(relevance.getReleField(),String.valueOf(archiveData.get(relevance.getFieldName())));
                                }
                            }
                            else if(relevance.getRelation() == 5){  //COUNT关系
                                int countData = archiveMapper.getCOUNTData(ids,category.getFileTableName());
                                data.put(relevance.getFieldName(),String.valueOf(countData));
                            }else if(relevance.getRelation() == 6){  //SUM关系
                                int sumData = archiveMapper.getSUMData(YqDatabaseSQLUtil.YQ_ISNULL("SUM("+relevance.getReleField()+")","0"),ids,category.getFileTableName());
                                data.put(relevance.getFieldName(),String.valueOf(sumData));
                            }
                        }else {
                            if(relevance.getRelation() == 5){  //COUNT关系
                                data.put(relevance.getFieldName(),"0");
                            }else if(relevance.getRelation() == 6){  //SUM关系
                                data.put(relevance.getFieldName(),"0");
                            }
                        }
                    }
                    if(data.size()>0){
                        if(relevance.getRelefieldLevel() == 1){
                            TenantYqFolder yqFolder = new TenantYqFolder();
                            yqFolder.setFolderId(id);
                            yqFolder.setColNames(data);
                            folderMapper.updateYqFolder(yqFolder);
                            yqFolder.setTableName(category.getFolderTableName());
                            folderMapper.updateYqFolderDisperse(yqFolder);
                        }else {
                            if(relevance.getRelation() == 0){
                                if(StringUtils.isNotEmpty(ids) && relevance.getRelefieldLevel() == 0){
                                    String [] daIds = ids.split(",");
                                    for(String daId:daIds){
                                        TenantYqda yqda = new TenantYqda();
                                        yqda.setDaId(Long.valueOf(daId));
                                        yqda.setColNames(data);
                                        yqdaMapper.updateYqda(yqda);
                                        yqda.setTableName(category.getFileTableName());
                                        yqdaMapper.updateYqdaDisperse(yqda);
                                    }
                                }
                            }else if(relevance.getRelation() == 5 || relevance.getRelation() == 6){
                                TenantYqFolder yqFolder = new TenantYqFolder();
                                yqFolder.setFolderId(id);
                                yqFolder.setColNames(data);
                                folderMapper.updateYqFolder(yqFolder);
                                yqFolder.setTableName(category.getFolderTableName());
                                folderMapper.updateYqFolderDisperse(yqFolder);
                            }
                        }
                    }
                }else if(type == 0){ //著录件
                    Map<String,String> data = new HashMap<>();
                    if(relevance.getRelefieldLevel() == 1){
                        if(relevance.getRelation() == 0) {
                            Map<String,Object> archiveData = archiveMapper.getArchiveDataById(relevance.getFieldName(),id,category.getFileTableName());
                            if(archiveData !=null && archiveData.get(relevance.getFieldName()) !=null && !"".equals(String.valueOf(archiveData.get(relevance.getFieldName())))){
                                data.put(relevance.getReleField(),String.valueOf(archiveData.get(relevance.getFieldName())));
                            }
                        }
                    }
                    if(data.size()>0){
                        TenantYqda yqda = new TenantYqda();
                        yqda.setDaId(id);
                        yqda.setColNames(data);
                        yqdaMapper.updateYqda(yqda);
                        yqda.setTableName(category.getFileTableName());
                        yqdaMapper.updateYqdaDisperse(yqda);
                    }
                    /*Map<String,Object> archiveData = archiveMapper.getArchiveDataById(relevance.getFieldName(),id,category.getFileTableName());
                    Map<String,String> data = new HashMap<>();
                    if(archiveData != null){
                        TenantYqdaFolder yqdaFolder = yqdaFolderMapper.selectByDaId(id,new TenantYqdaFolder().getTableName());  //关联关系
                        if(yqdaFolder !=null){
                            if(relevance.getRelefieldLevel() == 3){
                                if(yqdaFolder.getItemId()!=null){
                                    List<Object> itemData = archiveMapper.getDataDistinct(relevance.getReleField(),String.valueOf(yqdaFolder.getItemId()),category.getItemTableName());
                                    if(itemData !=null && itemData.size() == 1){ //等于关系
                                        data.put(relevance.getFieldName(),itemData.get(0).toString());
                                    }
                                }
                            }else if(relevance.getRelefieldLevel() == 1){
                                if(yqdaFolder.getFolderId()!=null){
                                    List<Object> folderData = archiveMapper.getDataDistinct(relevance.getReleField(),String.valueOf(yqdaFolder.getFolderId()),category.getFolderTableName());
                                    if(folderData !=null && folderData.size() == 1){ //等于关系
                                        data.put(relevance.getFieldName(),folderData.get(0).toString());
                                    }
                                }
                            }
                        }
                    }
                    if(data.size()>0){
                        TenantYqda yqda = new TenantYqda();
                        yqda.setDaId(id);
                        yqda.setColNames(data);
                        yqdaMapper.updateYqda(yqda);
                        yqda.setTableName(category.getFileTableName());
                        yqdaMapper.updateYqdaDisperse(yqda);
                    }*/
                }
            }
        }
    }
}
